package com.net.shop.car.manager.api.volley.request;

import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.net.shop.car.manager.api.model.ForPayGoods;
import com.net.shop.car.manager.api.volley.Request;
import com.net.shop.car.manager.utils.Constants;
import com.net.shop.car.manager.utils.LogUtils;

public class PostDingDan extends Request {
	
	private List<ForPayGoods> goods;
	private int payway;
	private String memberId;
	/**
	 * 
	 * @param goods
	 * @param payWay
	 *            支付方式，0代表线下支付（当面付），1代表线上支付
	 */
	public PostDingDan(List<ForPayGoods> goods, int payWay,String memberId) {
		super(Constants.CREATE_DINGDAN);
		this.goods = goods;
		this.payway = payWay;
		
		this.memberId = memberId;
	}

	@Override
	public void extensionJSON(JSONObject jsonObject) {
		try {
			jsonObject.put("pay_way", payway);
			jsonObject.put("member_id", memberId);
			JSONArray jsonArray = new JSONArray();
			for (ForPayGoods forPayGoods : goods) {
				JSONObject object = new JSONObject();
				object.put("pay_money", forPayGoods.getUseMoney());
				object.put("use_point", forPayGoods.getUseVb());
				object.put("good_id", forPayGoods.getGoodId());
				object.put("price", forPayGoods.getCheapPrice());
				jsonArray.put(object);
			}
			jsonObject.put("order", jsonArray);
		} catch (JSONException e) {
			LogUtils.e(e.getMessage());
		}
	}

}
